module.exports = function(args){
    args = args || {};
    var _this = this;
    this.size = 60;
    this.step = 1;
    var times = 0;
    this.timer = '';
    this.runing = false;
    this.id = 'timer' + new Date().getTime();
    a.Storage.set(this.id,true);
    this.run = function (interval){
        if(!this.runing){
            this.runing = true;
            times = this.size;
            this.timer = setInterval(function () {
                if(!_this.runing) return false;
                if(!a.Storage.get(_this.id)){
                    _this.stop(interval);
                    return false;
                }
                if (times <= 0) {
                    _this.stop(interval);
                } else {
                    times = times - _this.step;
                    if (typeof interval == 'function') interval.call(_this, times);
                }
            }, this.cycle || 1000);
        }
    }
    this.stop = function(fn){
        this.runing = false;
        times = 0;
        if(fn) fn.call(this,times);
        clearInterval(this.timer);
    }
    this.init = function(){
        this.runing = false;
        times = 0;
    }
    a.merge(this,args);
}